
/** OPTIONS, LIBREFS **/
OPTIONS MPRINT NOFMTERR PS=60 LS=80 sasautos =macro;
FILENAME macro "/disk/agedisk2/medicare.work/newhouse-DUA19577/jeff/programs/macro";

libname rg '/disk/agedisk2/medicare.work/newhouse-DUA19577/jeff/programs/measures/tables/regression/rru';
libname res '/disk/agebulk2/medicare.work/newhouse-DUA19577/jeff/DATA/results';
libname wk '/disk/agebulk2/medicare.work/newhouse-DUA19577/jeff/DATA/results';
libname wk9 '/disk/agebulk2/medicare.work/newhouse-DUA19577/jeff/DATA/results/2009';
libname wk8 '/disk/agebulk2/medicare.work/newhouse-DUA19577/jeff/DATA/results/2008';
libname wk7 '/disk/agebulk2/medicare.work/newhouse-DUA19577/jeff/DATA/results/2007';
libname wk6 '/disk/agebulk2/medicare.work/newhouse-DUA19577/jeff/DATA/results/2006';
libname wk5 '/disk/agebulk2/medicare.work/newhouse-DUA19577/jeff/DATA/results/2005';
libname wk4 '/disk/agebulk2/medicare.work/newhouse-DUA19577/jeff/DATA/results/2004';
libname wk3 '/disk/agebulk2/medicare.work/newhouse-DUA19577/jeff/DATA/results/2003';
libname ma '/disk/agebulk2/medicare.work/newhouse-DUA19577/jeff/DATA/MA_files';

x "/bin/rm /disk/agedisk2/medicare.work/newhouse-DUA19577/jeff/programs/measures/tables/regression/allcov*.sas7bdat";
x "/bin/rm /disk/agedisk2/medicare.work/newhouse-DUA19577/jeff/programs/measures/tables/regression/allf*.sas7bdat";

data rg;
 set rg.diab_comp;
proc sort;
 by org_id;

proc print;

***PLAN LEVEL MEASURE EXCLUSIONS;
data drop;
 set wk.selectplans (keep = org_id
 exc_cmc_07 exc_bcs_07
 exc_cdc1_07 exc_cdc3_07 exc_cdc4_07);
proc sort;
 by org_id;


***MATCHED MEASURE RESULTS;


data a;
 set wk.matched_qual_results_plan (keep = org_id ffs_07 hmo_07 meas);
 where meas in ("diab_hemo", "diab_ldl", "diab_retinal", "bcs", "ldl");
proc sort;
 by org_id;

data mg (drop = diab_comp_hmo diab_comp_ffs exc_cdc4_07 exc_cdc3_07 exc_cdc1_07
 exc_cmc_07 exc_bcs_07);
 merge a (in=aa) drop rg (in=r);
 by org_id;
 if aa;
 if r;

 if meas = "diab_ldl" and  exc_cdc4_07 = 1 then delete;
 if meas = "diab_retinal"  and exc_cdc3_07 = 1 then delete;
 if meas = "diab_hemo" and exc_cdc1_07 = 1 then delete;
 if meas = "bcs" and exc_bcs_07 = 1 then delete;
 if meas = "ldl" and exc_cmc_07 = 1 then delete;

proc sort;
 by meas;

proc means noprint;
 var ffs_07 hmo_07;
 class meas;
 output out=temp;

data sd (rename = (ffs_07=ffs_sd hmo_07=hmo_sd));
 set temp;
 where meas ~= "" and _stat_ = "STD";
 keep meas ffs_07 hmo_07;
proc sort;
 by meas;

data mn (rename = (ffs_07=ffs_mn hmo_07=hmo_mn));
 set temp;
 where meas ~= "" and _stat_ = "MEAN";
 keep meas ffs_07 hmo_07;
proc sort;
 by meas;


data mg;
 merge mg sd mn;
 by meas;

z_ffs = (ffs_07-ffs_mn)/ffs_sd;
z_hmo = (hmo_07-hmo_mn)/hmo_sd;

proc sort;
 by org_id;

proc sql;
 create table mg2 as select org_id, mean(z_ffs) as z_ffs, mean(z_hmo) as z_hmo, 
 max(sum_cost_ffs) as sum_cost_ffs, max(sum_cost_hmo) as sum_cost_hmo,
 mean(ffs_07) as ffs_07, mean(hmo_07) as hmo_07, max(taxstatus) as taxstatus,
 max(debut) as debut, max(affiliation) as affiliation, max(size) as size
 from mg
 group by org_id;



data mg2;
 set mg2; 
 file "diab_comp2.txt";
 if _n_ = 1 then do;
 put " org_id, " @;
 put " sumcosthmo, " @;
 put " sumcostffs, " @;
 put " debut, " @;
 put " allcomphmo, " @;
 put " allcompffs, " @;
 put " affiliation, " @;
 put " taxstatus, " @;
 put " size";
end;

 put org_id "," sum_cost_hmo "," sum_cost_ffs "," debut ","
 hmo_07 "," ffs_07 "," affiliation "," taxstatus "," size;




 diff_cost = sum_cost_hmo - sum_cost_ffs;
 diff_meas = hmo_07 - ffs_07;

label diff_cost = "HMO cost - FFS cost"
 diff_meas = "HMO diab comp - FFS disb_comp";

proc corr;
 var diff_cost diff_meas;


 












